<%--
 * edit.jsp
 *
 * Copyright (C) 2013 Universidad de Sevilla
 * 
 * The use of this project is hereby constrained to the conditions of the 
 * TDG Licence, a copy of which you may download from 
 * http://www.tdg-seville.info/License.html
 --%>

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="security"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@taglib prefix="acme" tagdir="/WEB-INF/tags"%>


<form:form action="${requestURI }" modelAttribute="challenge">
	<form:hidden path="event" />
	<form:hidden path="id" />
	
	<jstl:if test="${challengeOwner && eventNotStarted}">
		<acme:textbox code="challenge.title" path="title" />
		<acme:textbox code="challenge.description" path="description" />

		<jstl:if test="${hasResult}">
			<acme:textbox code="challenge.result" path="result" />
		</jstl:if>

		<jstl:if test="${isNew}">
			<acme:submit code="challenge.create" name="save" />
		</jstl:if>

		<jstl:if test="${!isNew}">
			<acme:submit code="challenge.update" name="save" />
			<input type="submit" name="delete"
				value="<spring:message code="challenge.delete" />"
				onclick="return confirm('<spring:message code = "challenge.confirm.delete"/>')" />
		</jstl:if>

	</jstl:if>

	<jstl:if test="${!challengeOwner}">
		<acme:textbox code="challenge.title" path="title" readonly="true" />
		<acme:textbox code="challenge.description" path="description"
			readonly="true" />

		<jstl:if test="${hasResult}">
			<acme:textbox code="challenge.result" path="result" readonly="true" />
		</jstl:if>

	</jstl:if>

	<security:authorize access="hasRole('ADMINISTRATOR')">
		<acme:cancel code="challenge.goBack" url="${backURI}" />
	</security:authorize>
	
	<security:authorize access="hasRole('PARTICIPANT')">
		<acme:cancel code="challenge.goBack" url="${backURI}" />
	</security:authorize>
	
	<security:authorize access="isAnonymous()">
		<acme:cancel code="challenge.goBack" url="${backURI}" />
	</security:authorize>
</form:form>